package servlet.PropertyManagementModule.ExpenseTypeManagement;

import bean.pojo.ExpenseType;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import commons.r.R;
import service.ExpenseTypeService;
import service.impl.ExpenseTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * servlet.PropertyManagementModule.ExpenseTypeManagement
 * User: xlh
 * Date: 2024/12/17 15:32
 * motto:推到高塔
 * Description:
 * Version: V1.0
 */
@WebServlet(name="ExpenseTypeAddServlet",value="/expenseType/addExpenseType")
public class ExpenseTypeAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        BufferedReader bufferedReader=request.getReader();
        String  req_data=bufferedReader.readLine();
        String dateFormat = "yyyy-MM-dd";
        ExpenseType expenseType= JSONObject.parseObject(req_data,ExpenseType.class);
        ExpenseTypeService productService=new ExpenseTypeServiceImpl();

        boolean update = productService.insert(expenseType);
        R r=!update? R.error("添加失败"):R.ok();
        //
        PrintWriter writer = response.getWriter();
        String  result= JSON.toJSONString(r);
        System.out.println("AddServlet:"+result);
        writer.write(result);
        writer.flush();
        writer.close();
    }
}
